package xing.appwidget.bean

import android.content.pm.PackageManager
import android.graphics.drawable.Drawable
import com.google.gson.Gson

data class ApplicationItem constructor(
        var appName: String,
        var packageName: String,
        var appIcon: Drawable?,
        var enabled: Boolean,
        var label: String,
        var versionName: String,
        var sdk: Int,
        var uid: Int
) {

    fun loadIcon(pm: PackageManager): Drawable {
        try {
            return pm.getApplicationIcon(packageName)
        } catch (ignore: Throwable) {
        }
        return pm.defaultActivityIcon
    }

    override fun toString(): String {
        return Gson().toJson(this);
    }

}